module.exports = ()=>{
  return async (ctx, next)=>{
    if (ctx.method === 'GET' && ctx.url.split('?')[0] === '/getData.jsonp') {
      let callbackName = ctx.query.callback || 'callback';
      let returnData = {
        success: true,
        data: {
          text: 'this is a jsonp api',
          time: new Date().getTime(),
        },
      };
      let jsonpStr = `;${callbackName}(${JSON.stringify(returnData)})`;
      ctx.type = 'text/javascript';
      ctx.body = jsonpStr;
    } else {
      next && await next();// 这边如果是jsonp请求的话，就不进行接下来的操作了
    }
  };
};
